package boerse.main.Gui;


import boerse.main.Asset.Share;
import boerse.main.Comparator.ShareComparator;
import boerse.main.StockPriceProvider.StockPriceInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Timer;

/**
 * Created with IntelliJ IDEA.
 * User: 13102012
 * Date: 02.05.13
 * Time: 15:27
 * To change this template use File | Settings | File Templates.
 */
public class GuiLoaderImpl implements GuiLoader{

    private StockPriceInfo priceInfo;
    private ArrayList<Share> allShare;
    private Timer timer;

    public GuiLoaderImpl(StockPriceInfo priceInfo) {
        this.priceInfo = priceInfo;
        Share[] s = priceInfo.getAllShares();
        this.allShare = new ArrayList<Share>();
        
        for (int i= 0; i < s.length; i++) {
        	allShare.add(s[i]);
        }

        ShareComparator comparator = new ShareComparator();
        Collections.sort(allShare, comparator);
        
        this.timer = priceInfo.getTime();
    }

    public void drawGraph(String shareName) {
        Share searchedShare = priceInfo.getShare(shareName);
        DrawGraph myFrame = new DrawGraph(searchedShare,priceInfo.getTime());

        myFrame.start(myFrame, searchedShare, priceInfo.getTime());
    }

    public void showTicker() {
    	Share[] s = new Share[allShare.size()];
        ViewerDemo viewer = new ViewerDemo(allShare.toArray(s));
        viewer.start(timer);
    }
}
